using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;

namespace CollegeShop.Infrastructure.Entities.Repository
{
    [Table("T_Centalstock")]
    public class T_Centalstock : IEntity<T_Centalstock>
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int GoodsID { get; set; }

        public int ActualStock { get; set; }

        public int FrozenStock { get; set; }

        public int WarningValue { get; set; }

        public override T_Centalstock Find(string key)
        {
            int id = Int32.Parse(key);
            return Find(c => c.GoodsID == id);
        }

        public override T_Centalstock Find(System.Linq.Expressions.Expression<Func<T_Centalstock, bool>> where)
        {
            using (Context ctx = new Context())
            {
                var item = ctx.Centalstock.FirstOrDefault(where);
                if (item != null)
                {
                    this.GoodsID = item.GoodsID;
                    this.ActualStock = item.ActualStock;
                    this.FrozenStock = item.FrozenStock;
                    this.WarningValue = item.WarningValue;
                    return this;
                }
                return null;
            }
        }

        public override bool Any(System.Linq.Expressions.Expression<Func<T_Centalstock, bool>> where)
        {
            using (Context ctx = new Context())
            {
                return ctx.Centalstock.Any(where);
            }
        }
    }
}
